package com.yoyo.service.impl;

import com.yoyo.dao.PetDao;
import com.yoyo.entity.Pet;
import com.yoyo.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetServiceimpl implements PetService {
    @Autowired
    private PetDao petDao;
    public List<Pet> findAll(Pet pet) {
        System.out.println("+++++++++++++++++++++impl"+petDao.findAll(pet));
        return petDao.findAll(pet);
    }

    public int delete(int id) {
        return petDao.delete(id);
    }

    public int save(Pet pet) {
        return petDao.save(pet);
    }

    public int bacthDel(String ids) throws Exception{
        String id [] = ids.split(",");
        int i = 0;
        for(String temp:id){
            i += petDao.delete(Integer.parseInt(temp));
        }
        if(i!=id.length){
            throw  new Exception("删除失败,记录可能已被删除!");
        }
        return i;
    }

    public Pet selById(int id) {
        return petDao.getById(id);
    }

    public int updPet(Pet pet) {
        return petDao.updPet(pet);
    }
}
